<%
/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */
%>

<%@ include file="/html/portlet/message_boards/init.jsp" %>


<%		
	List<MBThread> allThreads = MBThreadLocalServiceUtil.getMBThreads(0, MBThreadLocalServiceUtil.getMBThreadsCount());
	
	
	MBThread mostViewedThread = null;	
	
	List<MBThread> topThreads = new java.util.ArrayList<MBThread>();
	
	for(int i = 0;i<5;i++){
		for(MBThread thread : allThreads){
			if(mostViewedThread == null || thread.getViewCount() > mostViewedThread.getViewCount()){
				mostViewedThread = thread;
			}
		}
		if(!topThreads.contains(mostViewedThread)){
			topThreads.add(mostViewedThread);
		}
	}
	
	out.println(topThreads.size());

%>


<liferay-ui:search-container-row
				className="com.liferay.portlet.messageboards.model.MBThread"
				keyProperty="threadId"
				modelVar="thread"
			>
			
			
</liferay-ui:search-container-row>



<liferay-ui:search-container-results
			results = "<%= topThreads %>"
			total = "<%= topThreads.size() %>"
		/>
<liferay-ui:search-container-row
						className="com.liferay.portlet.messageboards.model.MBThread"
						keyProperty="threadId"
						modelVar="thread"
					>
						<%
						MBMessage message = MBMessageLocalServiceUtil.getMessage(thread.getRootMessageId());

						message = message.toEscapedModel();

						boolean readThread = MBMessageFlagLocalServiceUtil.hasReadFlag(themeDisplay.getUserId(), thread);

						row.setBold(!readThread);
						row.setObject(new Object[] {message, threadSubscriptionClassPKs});
						row.setRestricted(!MBMessagePermission.contains(permissionChecker, message, ActionKeys.VIEW));
						%>

			<liferay-portlet:renderURL varImpl="rowURL">
				<portlet:param name="struts_action" value="/message_boards/view_message" />
				<portlet:param name="messageId" value="<%= String.valueOf(message.getMessageId()) %>" />
			</liferay-portlet:renderURL>
    	</liferay-ui:search-container-row>	